package com.heima.admin.controller.v1;

import com.heima.admin.service.IAdChannelService;
import com.heima.model.admin.dtos.AdChannelDTO;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "频道数据接口")
@RestController
@RequestMapping("api/v1/channel")
public class AdChannelController {

    @Autowired
    private IAdChannelService adChannelService;

    @ApiOperation(value = "查询频道", notes = "根据名称分页查询频道列表")
    @PostMapping("list")
    public ResponseResult list(@RequestBody AdChannelDTO adChannelDTO){
        return adChannelService.list(adChannelDTO);
    }

    @ApiOperation(value = "新增频道", notes = "新增频道")
    @PostMapping("save")
    public ResponseResult insert(@RequestBody AdChannel adChannel){
        return adChannelService.insert(adChannel);
    }

    @ApiOperation(value = "修改频道", notes = "修改频道")
    @PostMapping("update")
    public ResponseResult update(@RequestBody AdChannel adChannel){
        return adChannelService.update(adChannel);
    }

    @ApiOperation(value = "删除频道", notes = "根据频道 ID 删除频道信息")
    @GetMapping("del/{id}")
    public ResponseResult delete(@PathVariable("id") Integer id){
        return adChannelService.delete(id);
    }

    @ApiOperation(value = "查询频道列表", notes = "查询频道列表")
    @GetMapping("channels")
    public ResponseResult channels(){
        List<AdChannel> adChannelList = adChannelService.list();
        return ResponseResult.okResult(adChannelList);
    }

    @ApiOperation(value = "根据 id 查询频道信息", notes = "leadnews-article 微服务处理文章发布")
    @PostMapping("channel")
    public ResponseResult<AdChannel> findChannelById(@RequestParam Integer channelId){
        return adChannelService.findChannelById(channelId);
    }
}
